package com.hnucm.c201901020121.Utils.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public class LooperPagerAdapter  extends PagerAdapter {
    private List<Integer> mColors=null;
    @Override
    public int getCount() {
        if(mColors!=null){
            return Integer.MAX_VALUE;
        }

        return 0;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        position=position%mColors.size();
        ImageView imageView=new ImageView(container.getContext());
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundColor(mColors.get(position));
        //imageView.setImageResource(mColors.get(position));
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        //super.destroyItem(container, position, object);
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }
    public  void setDate(List<Integer> colos){
        this.mColors=colos;
    }
    public int getDateRealSize(){
        if(mColors!=null) {
            return mColors.size();
        }
            return 0;
    }
}
